#region Microsoft Public License
/*
 * (c) Copyright Chenjun Wu. http://utablesdk.codeplex.com
 * 
 * This source is subject to the Microsoft Public License (Ms-PL).
 * Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
 * All other rights reserved.
 */
#endregion

﻿using System;

namespace UTable.Input
{
    public class InputEventArgs
    {
        private long _timestamp;
        private bool _handled = false;
        private bool _routeDown = true;
        private object _originalSource = null;
        
        public InputEventArgs(long timestamp)
        {
            this._timestamp = timestamp;
        }

        //
        // Summary:
        //     Gets the time when this event occurred.
        //
        // Returns:
        //     The timestamp.
        public long Timestamp
        {
            get { return _timestamp; }
        }

        /// <summary>
        ///  Gets or sets a value that indicates the present state of the event handling
        ///  for a routed event as it travels the route.
        /// </summary>
        /// <return>
        /// If setting, set to true if the event is to be marked handled; otherwise false.
        /// If reading this value, true indicates that either a class handler, or some
        /// instance handler along the route, has already marked this event handled.
        /// false.indicates that no such handler has marked the event handled.  
        /// 
        /// The control that is receiving this event can respond to it differently according to 
        /// this value. Especially, the object will not be moved by the finger 
        /// if the finger's event is handled in the control tree
        /// 
        /// The default value is false.
        /// </return>
        public bool Handled
        {
            get { return _handled; }
            set { _handled = value; }
        }

        /// <summary>
        /// Gets or sets a value that indicates whether this event should be route down
        /// </summary>
        /// <return>
        /// If set to true, then the event will be routed to the control below the control receiving this event;
        /// otherwise false. 
        /// The default value is false
        /// </return>
        public bool RouteDown
        {
            get { return _routeDown; }
            set { _routeDown = value; }
        }

        //
        // Summary:
        //     Gets the original reporting source as determined by pure hit testing
        //
        // Returns:
        //     The original reporting source
        //
        public object OriginalSource
        {
            get { return _originalSource; }
            internal set { _originalSource = value; }
        }

        public static long GetTimestamp(DateTime dateTime)
        {
            TimeSpan ts = dateTime - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(2009, 1, 1));
            return (long)Convert.ToUInt64(ts.TotalMilliseconds);
        }

        public static long GetTimestamp()
        {
            TimeSpan ts = DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(2009, 1, 1));
            return (long)Convert.ToInt64(ts.TotalMilliseconds);
        }
    }
}
